/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlets;

import com.mysql.jdbc.Blob;
import util.Proceso;
import com.sun.grizzly.tcp.Request;
import com.sun.grizzly.websockets.ProtocolHandler;
import com.sun.grizzly.websockets.WebSocket;
import com.sun.grizzly.websockets.WebSocketApplication;
import com.sun.grizzly.websockets.WebSocketListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import util.archivo;
/**
 *
 * @author johnny
 */
public class CorreoAplication extends WebSocketApplication{
    @Override
    public boolean isApplicationRequest(Request rqst) {
        if(rqst.requestURI().toString().endsWith("/index"))
            return true;
        else
            return false;
    }
    @Override
    public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
        return super.createWebSocket(protocolHandler, listeners);
    }

    @Override
    public boolean remove(WebSocket socket) {
        return super.remove(socket);
    }
    
    @Override
    public void onMessage(WebSocket socket, String text) {
        super.onMessage(socket, text);
        Proceso proc = new Proceso();
        socket.send(proc.procesaMensaje(text));
    }   

    @Override
    public void onMessage(WebSocket socket, byte[] bytes) {
        super.onMessage(socket, bytes);
   
   try { 
     OutputStream out = new FileOutputStream(archivo.nombre); 
     out.write(bytes); 
     out.close();         
     
   } catch (Exception e) { 
     e.printStackTrace(); 
   }         
     
    }
    
}
